﻿@model QuanLyGiaoVuUI.Models.TienDoDeTai.DeTaiViewModel

@{
    Layout = null;
}

<style>
    #themDeTaiDialog {
        background: white !important;
    }
    .suadetai {
        width:100%;
    }
</style>

<div>
    <div>
        <input type="hidden" id="maDeTai2" value="" />
        <table style="width: 90%;margin: 0 auto;">
            <tr>
                <td>Đề tài:</td>
                <td><input type="text" class="suadetai" id="tenDeTai2" value="" /></td>                
            </tr>
            <tr>
                <td>GV1:</td>
                <td>@Html.DropDownList("gvHD12", new SelectList(Model.danhSachGiangVien, "ID", "HoTenGV"), new { @class = "styledselect_form_1" })</td>
            </tr>
            <tr>
                <td>GV2:</td>
                <td>@Html.DropDownList("gvHD22", new SelectList(Model.danhSachGiangVien, "ID", "HoTenGV"), new { @class = "styledselect_form_1" })</td>
            </tr>
            <tr>
                <td>SV1:</td>
                <td>@if (Model.sinhVien1 != null)
                    {
                        <input type="text" id="sv12" value="@Model.sinhVien1.MaSinhVien" />
                        <span>SVTH:</span><span id="namesv12">@Model.sinhVien1.HoTenSV</span>                    
                    }
                    else
                    {
                        <input type="text" id="sv12" value="" />
                        <span>SVTH:</span><span id="namesv12"></span>
                    }
                </td>
            </tr>
            <tr>
                <td>SV2:</td>
                <td>@if (Model.sinhVien2 != null)
                    {
                        <input type="text" id="sv22" value="@Model.sinhVien2.MaSinhVien" /> 
                        <span>SVTH:</span><span id="namesv22">@Model.sinhVien2.HoTenSV</span>
                    }
                    else
                    {
                        <input type="text" id="sv22" value="" />
                        <span>SVTH:</span><span id="namesv22"></span>
                    }                    
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <a href="#" id="checknameSV2" style="color:red;margin:10 auto;">Kiểm tra sinh viên</a>
                </td>
            </tr>
            <tr>
                <td>Đủ đk bảo vệ:</td>
                <td>
                         <input type="checkbox" id="isKhoaLuan2" value="0" />
                </td>
            </tr>
            <tr>
                <td>Mô tả:</td>
                <td><textarea id="moTa2" class="suadetai" cols="11" rows="5"></textarea></td>
            </tr>
            <tr>
                <td>Đạt yêu cầu:</td>
                <td>
 
                         <input type="checkbox" id="isDatYeuCau2" value="" />
                </td>
            </tr>
            <tr>
                <td>Ghi chú:</td>
                <td><textarea id="ghiChu2" class="suadetai" cols="11" rows="5"></textarea></td>
            </tr>
            <tr>
                <td>File tài liệu:</td>
                <td>
                    <input type="text" class="suadetai" id="tenTaiLieu" value="" readonly="true" />
                    <input type="hidden" class="suadetai" id="fileTaiLieu" value="" />
                    <input type="button" id="btnChonTaiLieu" value="Chọn tài liệu" />
                </td>
                @*<td><td>@Html.DropDownList("fileTaiLieu", new SelectList(Model.danhSachTaiLieuLuanVan, "MaTaiLieu", "TenTapTin",@Model.DeTai.FileTaiLieu), new { @class = "fileTaiLieu" })</td></td>*@
            </tr>
            <tr>
                <td></td>
                <td><input type="button" id="luuDeTai2" value="Lưu" /></td>
            </tr>
        </table>        
    </div>
    <div>
        
    </div>
</div>

<div id="ChonTaiLieuDialog"></div>

<script type="text/javascript">
    var editor = CKEDITOR.replace('moTa2');
    //var ghichu = CKEDITOR.replace('ghiChu');
</script>

<script>
    $(document).ready(function () {
        $('#luuDeTai2').click(function () {
            var tendt = $('#tenDeTai2').val();
            var gvhd1 = $('#gvHD12').val();
            var gvhd2 = $('#gvHD22').val();
            var isKL = document.getElementById('isKhoaLuan2').checked;
            var mota = editor.getData();           
            var isDYC = document.getElementById('isDatYeuCau2').checked;
            var ghichu = $('#ghiChu2').val();
            var filetl = $('#fileTaiLieu').val();
            var maSV1 = $("#sv12").val();
            var maSV2 = $("#sv22").val();

            $.post("/TienDoDeTai/ThemDeTai",
                {tenDeTai: tendt, gvHD1: gvhd1, gvHD2: gvhd2, isKhoaLuanTN: isKL, moTa: mota, isDatYeuCau: isDYC, ghiChu: ghichu, fileTaiLieu: filetl, sv1: maSV1, sv2: maSV2 },
                function (data) {
                    //alert(data.message);
                    //if (data.success) {
                    //    $("#themTaiDialog").dialog("close");

                    //}
                    ThongBao(data);
                });
        });
        $("#checknameSV2").click(function () {
            var maSV1 = $("#sv12").val();
            var maSV2 = $("#sv22").val();
            $.post("/TienDoDeTai/CheckNameSinhVien/", { sv1: maSV1, sv2: maSV2 }, function (data) {
                //alert(data.sv1);
                //alert(data.sv2);
                $("#namesv12").html(data.sv1);
                $("#namesv22").html(data.sv2);
            });
        });

        $("#btnChonTaiLieu").each(function () {
            $(this).bind("click", function () {
                $("#ChonTaiLieuDialog").load("/TaiLieu/ChonTaiLieuDialog").dialog({
                    autoOpen: true,
                    width: 700,
                    height: 400,
                    title: "Chọn tài liệu",
                    buttons: {
                        "Chọn": function () {
                            if (ChonTaiLieuDialog.MaTaiLieu != null) {
                                $("#fileTaiLieu").val(ChonTaiLieuDialog.MaTaiLieu);
                                $("#tenTaiLieu").val(ChonTaiLieuDialog.TenTaiLieu);
                            }
                            $("#ChonTaiLieuDialog").dialog("close");
                        }
                    }
                });
            });
        });

        function reloadPage() {
            window.location = "/TienDoDeTai/DeTai/";
        }
        function ThongBao(data) {
            if (data.success) {
                ToastManager.showSuccessToast(data.message);
                setTimeout(function () {
                    reloadPage();
                }, 2000);
            }
            else {
                ToastManager.showStickyWarningToast(data.message);
            }
        }

    });
</script>